home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / src / list / qu2ls_send.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-28  |  8.5 KB  |  380 lines

  1. #
  2. /*
  3.  *     MULTI-CHANNEL MEMO DISTRIBUTION FACILITY  (MMDF)
  4.  *
  5.  *     Copyright (C) 1979,1980,1981  University of Delaware
  6.  *
  7.  *     Department of Electrical Engineering
  8.  *     University of Delaware
  9.  *     Newark, Delaware  19711
  10.  *
  11.  *     Phone:  (302) 738-1163
  12.  *
  13.  *     This program module was developed as part of the University
  14.  *     of Delaware's Multi-Channel Memo Distribution Facility (MMDF).
  15.  *
  16.  *     Acquisition, use, and distribution of this module and its listings
  17.  *     are subject restricted to the terms of a license agreement.
  18.  *     Documents describing systems using this module must cite its source.
  19.  *
  20.  *     The above statements must be retained with all copies of this
  21.  *     program and may not be removed without the consent of the
  22.  *     University of Delaware.
  23.  *
  24.  *
  25.  *     version  -1    David H. Crocker    March   1979
  26.  *     version   0    David H. Crocker    April   1980
  27.  *     version  v7    David H. Crocker    May     1981
  28.  *     version   1    David H. Crocker    October 1981
  29.  *
  30.  */
  31. /*                SEND FROM DELIVER TO SUBMIT
  32.  *
  33.  *  Feb 83  Doug Kingston       Initial version of list processor
  34.  *  Apr 86  Craig Partridge     Minor efficiency tweaking
  35.  */
  36.  
  37. #include "util.h"
  38. #include "mmdf.h"
  39. #include "phs.h"
  40. #include "ch.h"
  41. #include "ap.h"
  42. #include <pwd.h>
  43.  
  44. extern struct ll_struct   *logptr;
  45. extern Chan *chanptr;
  46. extern long qu_msglen;
  47. extern char *supportaddr;
  48.  
  49. extern char *rindex();
  50. extern char *strdup();
  51. extern char *multcat();
  52. extern char *blt();
  53.  
  54. char *findreturn();
  55.  
  56. LOCFUN qu2ls_each(), qu2ls_txtcpy();
  57.  
  58. LOCVAR int nadrs;
  59. LOCVAR char sender[ADDRSIZE];
  60.  
  61. LOCVAR struct rp_construct
  62.     rp_bdrem =
  63. {
  64.     RP_BHST, 'B', 'a', 'd', ' ', 'r', 'e', 's', 'p', 'o', 'n', 's', 'e',
  65.     ' ', 'f', 'r', 'o', 'm', ' ', 's', 'u', 'b', 'm', 'i', 't', '\0'
  66. },
  67.     rp_adr =
  68. {
  69.     RP_AOK, 'a', 'd', 'd', 'r', 'e', 's', 's', ' ', 'o', 'k', '\0'
  70. },
  71.     rp_gdtxt =
  72. {
  73.     RP_MOK, 't', 'e', 'x', 't', ' ', 's', 'e', 'n', 't', ' ', 'o', 'k', '\0'
  74. },
  75.     rp_noop =
  76. {
  77.     RP_NOOP, 's', 'u', 'b', '-', 'l', 'i', 's', 't', ' ', 'n', 'o', 't', ' ',
  78.     's', 'p', 'e', 'c', 'i', 'a', 'l', '\0'
  79. };
  80.  
  81. /* */
  82.  
  83. qu2ls_send ()             /* overall mngmt for batch of msgs    */
  84. {
  85.     int     started = FALSE;
  86.     short       result;
  87.     char        info[LINESIZE];
  88.  
  89. #ifdef DEBUG
  90.     ll_log (logptr, LLOGBTR, "qu2ls_send ()");
  91. #endif
  92.  
  93.     if (rp_isbad (result = qu_pkinit ()))
  94.     return (result);
  95.  
  96.     /*
  97.      *  While there are messages to process ...
  98.      */
  99.     for(;;){                /* get initial info for new message   */
  100.     result = qu_rinit (info, sender, chanptr -> ch_apout);
  101.  
  102.     switch(rp_gval(result)) {
  103.  
  104.         case RP_NS:
  105.         case RP_FIO:
  106.         qu_rend();
  107.         continue;
  108.  
  109.         case RP_OK:
  110.         break;
  111.  
  112.         default:
  113.         goto done;
  114.     }
  115.  
  116.     /* make sure submit is running */
  117.  
  118.     if ((!started) && (rp_isbad(mm_init()) || rp_isbad(mm_sbinit()))) {
  119.         /* quit... */
  120.         ll_log(logptr, LLOGTMP, "couldn't start submit");
  121.         goto done;
  122.     }
  123.     started = TRUE;
  124.  
  125.     switch (rp_gval (result = qu2ls_each())) {
  126.  
  127.         case RP_OK:
  128.         case RP_MECH:
  129.         break;
  130.  
  131.         case RP_BTNO:    /*  submit was difficult */
  132.         started = FALSE;
  133.         break;
  134.  
  135.         case RP_BNO:    /* deliver was difficult */
  136.         default:
  137.         goto done;
  138.     }
  139.  
  140.     qu_rend();
  141.     }
  142.  
  143. done:
  144.     qu_rend();
  145.  
  146.     if (rp_gval (result) != RP_DONE) {
  147.     ll_log (logptr, LLOGFAT, "not DONE (%s)", rp_valstr (result));
  148.     return (RP_RPLY);         /* catch protocol errors              */
  149.     }
  150.  
  151.     if (started) {
  152.     mm_sbend();
  153.     mm_end(OK);
  154.     }
  155.  
  156.     qu_pkend ();                  /* done getting messages              */
  157.     return (result);
  158. }
  159. /* */
  160.  
  161. LOCFUN
  162.     qu2ls_each ()             /* send copy of text per address      */
  163. {
  164.     struct rp_bufstruct thereply;
  165.     short   result;
  166.     int     len;
  167.     char    host[ADDRSIZE];
  168.     char    adr[ADDRSIZE];
  169.     char    *retadr;
  170.     char    *p;
  171.     int     ndone=0;
  172.  
  173. #ifdef DEBUG
  174.     ll_log (logptr, LLOGBTR, "qu2ls_each()");
  175. #endif
  176.  
  177.     nadrs = 0;
  178.  
  179.     /*
  180.      *  For every address in the message ...
  181.      */
  182.     while( 1 ) {
  183.     result = qu_radr (host, adr);
  184.     if (rp_isbad (result))
  185.         return (RP_BNO);      /* get address from Deliver           */
  186.  
  187.     switch (rp_gval (result))
  188.     {
  189.         case RP_HOK:          /* end of sub-list */
  190.         qu_wrply ((RP_Buf *)&rp_noop, sizeof rp_noop);
  191.         break;
  192.  
  193.         case RP_DONE:         /* end of full address list           */
  194.         if (ndone != 0)
  195.             qu2ls_txtcpy(&thereply);
  196.         else
  197.             blt((char *)&rp_bdrem,(char *)&thereply,sizeof rp_bdrem);
  198.  
  199.         qu_wrply(&thereply, sizeof (thereply.rp_val) +
  200.             strlen (thereply.rp_line));
  201.  
  202.         if (ndone == 0 || rp_isbad(thereply.rp_val)) {
  203.             mm_end(NOTOK);
  204.             return(RP_BTNO);
  205.         }
  206.         return (RP_OK);         /* END for this message */
  207.  
  208.         default:            /* actually have an address */
  209.         /* Strip host reference if there */
  210.         if (p = rindex (adr, '@'))
  211.             *p = '\0';
  212.  
  213.         if (nadrs++ == 0)
  214.         {
  215.             if ((retadr = findreturn(adr)) == (char *)NULL)
  216.             retadr = sender;
  217.  
  218.             /* should allow W to be passed here */
  219.             if (rp_isbad (mm_winit (chanptr->ch_name, "tlzvm", retadr))
  220.               || rp_isbad (mm_rrply(&thereply, &len))) {
  221.             mm_end (NOTOK);
  222.             printx ("Error in submit startup\n");
  223.             fflush (stdout);
  224.             qu_wrply((RP_Buf *)&rp_bdrem, sizeof rp_bdrem);
  225.             return(RP_BTNO);
  226.             }
  227.  
  228.             switch (rp_gbval (thereply.rp_val)) {
  229.             case RP_BNO:
  230.             case RP_BTNO:
  231.             mm_end (NOTOK);
  232.             printx ("Error in submit startup (%s)\n", thereply.rp_line);
  233.             fflush (stdout);
  234.             qu_wrply(&thereply, len);
  235.             return(RP_BTNO);
  236.             }
  237.             if (rp_isbad (mm_wadr ("", adr))
  238.              || rp_isbad (mm_rrply(&thereply, &len))) {
  239.             mm_end (NOTOK);
  240.             printx ("Error in submit startup\n");
  241.             fflush (stdout);
  242.             qu_wrply((RP_Buf *)&rp_bdrem, sizeof rp_bdrem);
  243.             return(RP_BTNO);
  244.             }
  245.         }
  246.         else
  247.         {
  248.             if (rp_isbad (mm_wadr ("", adr))
  249.                || rp_isbad (mm_rrply(&thereply, &len)))
  250.             {
  251.             mm_end (NOTOK);
  252.             printx ("Error in passing address\n");
  253.             fflush (stdout);
  254.             qu_wrply((RP_Buf *)&rp_bdrem, sizeof rp_bdrem);
  255.             return(RP_BTNO);
  256.             }
  257.         }
  258.  
  259.         switch (rp_gval (thereply.rp_val))
  260.         {                 /* was address acceptable?            */
  261.             case RP_AOK:
  262.             case RP_DOK:
  263.             qu_wrply((RP_Buf *)&rp_adr, sizeof  rp_adr);
  264.             ndone++;
  265.             continue;
  266.  
  267.             case RP_PARM:
  268.             case RP_USER:
  269.             case RP_NO:
  270.             case RP_NS:
  271.             break;    /* report failure and continue        */
  272.  
  273.             case RP_RPLY:
  274.             ll_log (logptr, LLOGTMP, "unusual return: (%s)%s",
  275.                 rp_valstr (thereply.rp_val), thereply.rp_line);
  276.             break;    /* notify deliver */
  277.         }
  278.         /* tell deliver about all this */
  279.         qu_wrply (&thereply, len);
  280.     } /* end switch */
  281.     }
  282.     /* NOTREACHED */
  283. }
  284.  
  285. /* */
  286.  
  287. LOCFUN
  288.     qu2ls_txtcpy (rp)     /* copy the text of the message       */
  289. RP_Buf *rp;
  290. {
  291.     int       len;
  292.     short     result;
  293.     char      buffer[BUFSIZ];
  294.  
  295. #ifdef DEBUG
  296.     ll_log (logptr, LLOGBTR, "qu2ls_txtcpy()");
  297. #endif
  298.  
  299.     qu_rtinit (0L);
  300.  
  301.     if (rp_isbad (result = mm_waend())) {
  302.     blt ((char *)&rp_bdrem, (char *) rp, sizeof rp_bdrem);
  303.     return;
  304.     }
  305.  
  306.     printx ("sending...:");
  307.     fflush (stdout);
  308.  
  309.     len = sizeof(buffer);
  310.     while ((rp_gval (result = qu_rtxt (buffer, &len))) == RP_OK)
  311.     {
  312.     result = mm_wtxt (buffer, len);
  313.     if (rp_isbad (result))
  314.         break;
  315.     printx (".");
  316.     fflush (stdout);
  317.     if (rp_gval (result) != RP_OK) {
  318.         blt ((char *)&rp_bdrem, (char *) rp, sizeof rp_bdrem);
  319.         return;
  320.     }
  321.     len = sizeof(buffer);
  322.     }
  323.  
  324.     if (rp_isbad (result) || rp_gval (result) != RP_DONE) {
  325.     blt ((char *)&rp_bdrem, (char *) rp, sizeof rp_bdrem);
  326.     return;
  327.     }
  328.  
  329.     if (rp_isbad(mm_wtend()) || rp_isbad(mm_rrply(rp,&len))) {
  330.     rp->rp_val = RP_RPLY;
  331.     strcpy(rp->rp_line,"Unknown problem");
  332.     return;
  333.     }
  334.  
  335.     blt ((char *)&rp_gdtxt, (char *)rp, sizeof rp_gdtxt);
  336. }
  337.  
  338. /********************/
  339.  
  340. char *
  341. findreturn (adr)
  342. char *adr;
  343. {
  344.     extern struct passwd *getpwmid();
  345.     char newretadr[ADDRSIZE];
  346.     char *msg = "Changing return address to '%s'\n";
  347.     char *key;
  348.     char *cp;
  349.  
  350.     printx ("\n\t");
  351.     key = multcat (adr, "-request", (char *)0);
  352.  
  353.     if (aliasfetch(TRUE, key, newretadr, 0) == OK)
  354.     goto done;
  355.     if (getpwmid(key) != NULL)
  356.     goto done;
  357.  
  358.     free (key);
  359.     key = strdup (adr);
  360.     if ((cp = rindex (key, '-')) && lexequ (cp, "-outbound")) {
  361.     *cp = 0;
  362.     cp = key;
  363.     key = multcat (key, "-request", (char *)0);
  364.     free (cp);
  365.     if (aliasfetch(TRUE, key, newretadr, 0) == OK)
  366.         goto done;
  367.     if (getpwmid(key) != NULL)
  368.         goto done;
  369.     }
  370.     free (key);
  371.  
  372.     /* If address goes thru list channel then take charge */
  373.     key = multcat ("List Manager <", supportaddr, ">", (char *)0);
  374.     msg = "Using default return address '%s'\n";
  375. done:
  376.     printx (msg, key);
  377.     fflush (stdout);
  378.     return (key);
  379. }
  380.